n = eval(input())
list1 = list(map(int, input().split()))
max_sum = 0
while True:
    if len(list1) != 0:
        if list1[0] < 0:
            list1.pop(0)
        else:
            break
    else:
        break

while True:
    if len(list1) != 0:
        if list1[len(list1)-1] < 0:
            list1.pop(len(list1)-1)
        else:
            break
    else:
        break

s = 0
for i in range(len(list1)):
    s += list1[i]
    if s < 0:
        s = 0
    if s > max_sum:
        max_sum = s

print(max_sum)